import Vue from 'vue';
import VueRouter from 'vue-router';
// import Home from '../views/Home.vue';
import user from './modules/user';
import news from './modules/news';
import properties from './modules/vmProperty';
import { IsPC } from '@/assets/js/utils';

Vue.use(VueRouter);

/* pc端路由表 */
const routes = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    name: 'Login',
    component:  IsPC() ? () => import('@/views/login/PcLogin') : () => import('@/views/login/MobileLogin'),
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue'),
  },
  {
    path: '/home',
    name: "Home",
    component: () => import('../views/Home.vue'),
  },
  user,
  news,
  properties,
];

/* 移动端路由表 */
const mobileRoutes = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/MobileLogin'),
  },
  {
    path: '/about',
    name: 'About',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue'),
  },
  {
    path: '/home',
    name: "Home",
    component: () => import('../views/Home.vue'),
  },
  user,
  news,
  properties,
];

// console.log('IsPc', IsPC())
// console.log('IsPc', navigator.userAgent)

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  // routes: IsPC() ? routes : mobileRoutes,
  routes: routes,
});

export default router;
